<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>汽车之家</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
    <meta name="x5-fullscreen" content="true">
    <meta name="full-screen" content="yes">
    <link rel="stylesheet" type="text/css" href="css/index.css">
    <script type="text/javascript">
        document.documentElement.style.fontSize = window.innerWidth/3.75 + 'px'
    </script>
</head>
<body>
<img id="finish" src="" style="display: none"/>
<a id="will_hide"  href="###">
    <div class="appBac">
        <div class="banner">
            <img id="car_images" src="">
        </div>
        <div class="img_wechat bg_fff">
            <div id="qrcode_app"></div>
            <p>长按图片保存<br />扫描二维码上“头条”</p>

        </div>
    </div>
</a>

<script src="js/jquery.js"></script>
<script src="js/common.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script src="js/jquery.qrcode.js"></script>
<script src="js/html2canvas.min.js"></script>


<script type="text/javascript">
    $(function () {

        $("#car_images").attr('src',localStorage.getItem('ret_url'))
        ret = new QRCode(document.getElementById("qrcode_app"), localStorage.getItem('share_url'));



        console.log("down");
        $.get("/index/jssdk", function (result) {
            wx.config(result);
            wx.ready(function () {
                console.log("ajax done");
                var text = localStorage.getItem('text')
                var name = localStorage.getItem('name')
                switch (text) {
                    case "1":text = '<span>XXX昨日怒提新车</span><span>“左手事业 右手家庭”</span>';break;
                    case "2":text = '<span>太膨胀！XXX买车眼都不眨</span><span>“要全款，我不喜欢贷款”</span>';break;
                    case "3":text = '<span>一高兴就买车，XXX真任性</span><span>“买台车而已，别惊讶”</span>';break;
                }
                html2canvas(document.querySelector('body')).then(function(canvas) {
                    $("#finish").attr('src',canvas.toDataURL("image/jpeg"));
                    $("#finish").attr('width',window.innerWidth);
                });

                $("#will_hide").on('touchstart mousedown',function(){
                    console.log('start')
                   $("#finish").show()
                    setTimeout(function(){
                        $("#finish").hide()
                    },1000);
                });
                $("#will_hide").on('touchend mouseup',function(){
                    setTimeout(function(){
                        console.log('end')

                        $("#finish").hide()
                    },500);
                });

                title = text.replace('XXX',name)
                title = title.replace(/<[^>]+>/g,"");

                var url = localStorage.getItem('share_url')

                wx.onMenuShareTimeline({  //例如分享到朋友圈的API
                    title: title, // 分享标题
                    link: url, // 分享链接
                    desc: title,
                    imgUrl: 'http://car.kphcdr.com/images/share_car1.png', // 分享图标
                    success: function () {
                        // 用户确认分享后执行的回调函数
                    },
                    cancel: function () {
                        // 用户取消分享后执行的回调函数
                    }
                });
                wx.onMenuShareAppMessage({
                    title: title, // 分享标题
                    link: url, // 分享链接
                    desc: title,
                    imgUrl: 'http://car.kphcdr.com/images/share_car1.png', // 分享图标
                    success: function () {
                        // 用户确认分享后执行的回调函数
                    },
                    cancel: function () {
                        // 用户取消分享后执行的回调函数
                    }
                });

            })
        })



    })

</script>
</body>
</html>